#pragma once

#include "Misc/CommonMacros.h"
#include <memory>
#include "Containers/Delegate.h"
#include "IPAddress.h"
#include "Containers/ThreadSafePtr.h"

class WHENGINE_API CUDPServer : public EnableThreadSafeSharedPtrFromThis<CUDPServer>
{
public:
    //may failed if port is already used
    static TThreadSafeSharedPtr<CUDPServer> Create(const SIPAddress& IP, uint16_t Port);

    CUDPServer(void* InPlatformSocket);
    ~CUDPServer();

    TDelegate<void
        ,TVector<uint8_t> /*Accepted Data*/ 
        ,SIPAddress /* IP */ 
        ,uint16_t /* Port */ > OnDataReceived;
protected:
    void* PlatformSocket = nullptr;

    void StartReciveTask();
};